package ControlLayer;
import ModelLayer.PurchaseContainer;
import ModelLayer.Purchase;
import ModelLayer.Product;
import ModelLayer.LineItem;
import java.util.ArrayList;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */
public class PurchaseCtr
{
    // instance variables
    private PurchaseContainer purchaseContainer;
    private ProductCtr productCtr;

    /**
     * Constructor for objects of class PurchaseCtr
     */
    public PurchaseCtr()
    {
        purchaseContainer = PurchaseContainer.getInstance();
        productCtr = new ProductCtr();
    }
    
    public void addPurchase(Purchase purchase) 
    {
        purchaseContainer.addPurchase(purchase);
    }
    
    public Purchase findPurchase(String id) 
    {
        return purchaseContainer.findPurchase(id);
    }
    
    public void updatePurchase(Purchase purchase,String id, String date) 
    {
        purchase.setId(id);
        purchase.setDate(date);
    }
    
    public void deletePurchase(Purchase purchase) 
    {
        purchaseContainer.deletePurchase(purchase);
    }

    public void addItem(Purchase purchase, String barcode, int quantity) 
    {
        Product product = productCtr.findProduct(barcode);
        if(product != null) 
        {
            LineItem lineItem = new LineItem(product,quantity);
            purchase.addLineItem(lineItem);
        }
    }
    
    public void removeItem(Purchase purchase, String barcode) 
    {
        Product product = productCtr.findProduct(barcode);
        if(product != null) 
        {
            purchase.removeLineItem(product);
        }
    }
    
    public void setDispatchDate(Purchase purchase, String dispatchDate) 
    {
        purchase.setDispatchDate(dispatchDate);
    }
    
    public void setDeliveryDate(Purchase purchase, String deliveryDate) 
    {
        purchase.setDeliveryDate(deliveryDate);
    }
    
    public ArrayList<Purchase> getPurchaseList() 
    {
     return purchaseContainer.getPurchaseList();
    }
}
